package com.dhl.rabbitmq.utils;

import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;

import com.rabbitmq.client.Channel;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

/**
 * 此类为连接工程创建信道的工具类
 * @title: RabbitMQUtils
 * @Author danghailiang
 * @Date: 2022/6/9 9:17
 * @Version 1.0
 */
public class RabbitUtils {
    public static Channel getChannel() throws Exception{
        // 创建连接工厂
        ConnectionFactory factory = new ConnectionFactory();
        // 工厂Ip 连接RabbitMQ队列
        factory.setHost("192.168.170.188");
        // 设置用户名
        factory.setUsername("admin");
        // 密码
        factory.setPassword("123456");
        factory.setConnectionTimeout(60);
        // 创建一个连接
        Connection connection = factory.newConnection();
        // 创建信道
        Channel channel = connection.createChannel();
        // 返回信道
        return channel;
    }
}
